package cn.safeness.web;

import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication(scanBasePackages = {"cn.safeness"})
@ServletComponentScan(basePackages = {"cn.safeness"})
@RestController
public class WebApplication {
	public static void main(String[] args) {
		SpringApplication.run(WebApplication.class, args);
	}

	@RequestMapping("/")
	public String Welcome() {
		return "Welcome to Safeness!";
	}

	// Druid 监控页面
	@Bean
	public ServletRegistrationBean testServletBean() {
		ServletRegistrationBean testServletRegistration = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
		testServletRegistration.addInitParameter("resetEnable", String.valueOf(true));
		testServletRegistration.addInitParameter("loginUsername", "admin");
		testServletRegistration.addInitParameter("loginPassword", "admin");
		return testServletRegistration;
	}
}
